import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'image_view.dart';

class ShareOption extends StatefulWidget {
  final String title;
  final String imagePath;
  final VoidCallback onTap;

  ShareOption({required this.title, required this.imagePath, required this.onTap});

  @override
  _ShareOptionState createState() => _ShareOptionState();
}

class _ShareOptionState extends State<ShareOption> {
  double _scale = 1.0; // 图片缩放比例

  void _onTapDown(TapDownDetails details) {
    setState(() {
      _scale = 0.9; // 按下时缩小
    });
  }

  void _onTapUp(TapUpDetails details) {
    setState(() {
      _scale = 1.0; // 松手恢复
    });
    widget.onTap(); // 触发点击事件
  }

  void _onTapCancel() {
    setState(() {
      _scale = 1.0; // 取消时恢复
    });
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTapDown: _onTapDown,
      onTapUp: _onTapUp,
      onTapCancel: _onTapCancel,
      child: Container(
        height: 104,
        margin: EdgeInsets.only(left: 15, top: 8),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            AnimatedContainer(
              duration: Duration(milliseconds: 100),
              width: 48 * _scale,
              height: 48 * _scale,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
              ),
              child: ImageView(widget.imagePath),
            ),
            SizedBox(height: 8),
            Text(
              widget.title,
              style: TextStyle(fontSize: 12, color: Colors.white),
              textAlign: TextAlign.center,
            ),
          ],
        ),
      ),
    );
  }
}
